package com.code.petapp.util;

import android.util.Log;

import com.code.petapp.bean.AdoptBean;
import com.code.petapp.bean.FosterBean;
import com.code.petapp.bean.GoodsBean;
import com.code.petapp.http.HttpApiService;
import com.code.petapp.http.HttpListener;
import com.code.petapp.http.RetrofitHelper;
import com.code.petapp.http.RxObserver;

import java.util.ArrayList;

public class FosterUtils {
    public static void selectAll(String token, HttpListener<ArrayList<FosterBean>> httpListener){
        Log.d("Tag","select start");
        new RetrofitHelper().createApi(HttpApiService.class)
                .selectAllFoster(token)
                .compose(RetrofitHelper.schedulersTransformer())
                .subscribe(new RxObserver<>() {
                    @Override
                    public void success(ArrayList<FosterBean> baseBean) {
                        httpListener.success(baseBean);
                    }

                    @Override
                    public void error(int code, String error) {
                        httpListener.error(code,error);
                    }
                });
    }
    public static void selectStatus(String token,String status, HttpListener<ArrayList<FosterBean>> httpListener){
        Log.d("Tag","selectStatus start");
        new RetrofitHelper().createApi(HttpApiService.class)
                .selectAllFosterS(token,status)
                .compose(RetrofitHelper.schedulersTransformer())
                .subscribe(new RxObserver<>() {
                    @Override
                    public void success(ArrayList<FosterBean> baseBean) {
                        httpListener.success(baseBean);
                    }

                    @Override
                    public void error(int code, String error) {
                        httpListener.error(code,error);
                    }
                });
    }
    public static void add(String token,FosterBean fosterBean, HttpListener<String> httpListener){
        Log.d("Tag","add start");
        new RetrofitHelper().createApi(HttpApiService.class)
                .fosterAdd(token,fosterBean)
                .compose(RetrofitHelper.schedulersTransformer())
                .subscribe(new RxObserver<>() {
                    @Override
                    public void success(String data) {
                        httpListener.success(data);
                    }

                    @Override
                    public void error(int code, String error) {
                        httpListener.error(code,error);
                    }
                });
    }
    public static void update(String token,FosterBean fosterBean, HttpListener<String> httpListener){
        Log.d("Tag","update start");
        new RetrofitHelper().createApi(HttpApiService.class)
                .fosterUpdate(token,fosterBean)
                .compose(RetrofitHelper.schedulersTransformer())
                .subscribe(new RxObserver<>() {
                    @Override
                    public void success(String data) {
                        httpListener.success(data);
                    }

                    @Override
                    public void error(int code, String error) {
                        httpListener.error(code,error);
                    }
                });
    }
    public static void delete(String token,int id, HttpListener<String> httpListener){
        Log.d("Tag","update start");
        new RetrofitHelper().createApi(HttpApiService.class)
                .fosterDelete(token,id)
                .compose(RetrofitHelper.schedulersTransformer())
                .subscribe(new RxObserver<>() {
                    @Override
                    public void success(String data) {
                        httpListener.success(data);
                    }

                    @Override
                    public void error(int code, String error) {
                        httpListener.error(code,error);
                    }
                });
    }
}
